<template>
  <div>
    <h2><span id="gun">丨</span> 评价管理</h2>
    <div id="search">
      <el-input
        v-model="searchValue"
        placeholder="请输入账号、姓名查询"
      ></el-input>
      <el-button type="primary" plain @click="search">查询</el-button>
    </div>

    <el-table :data="showTableData" border style="width: 100%">
      <el-table-column prop="date" label="订单号"> </el-table-column>
      <el-table-column label="评价">
        <template slot-scope="scope">
          <el-rate
            v-model="scope.row.score"
            disabled
            show-score
            text-color="#ff9900"
            score-template="{value}"
          >
          </el-rate>
        </template>
      </el-table-column>
      <el-table-column prop="orderComment" label="评价内容">
        <template slot-scope="scope">
          <div>
            <p>{{ scope.row.orderComment }}</p>
            <img
            :src=" Httphead + '/' + scope.row.orderCommentPicture"
            alt=""
            width="60"
            height="60"
            style="border-radius: 50%"
            />
          </div>
          
        </template>
      </el-table-column>
      <el-table-column prop="user.name" label="用户昵称"> </el-table-column>
      <el-table-column prop="user.phone" label="联系手机"> </el-table-column>
      <el-table-column prop="project.name" label="企业"> </el-table-column>

      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="del(scope.row.id)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <div class="block">
      <span class="demonstration"></span>
      <el-pagination
        layout="total, sizes,prev, pager, next,jumper"
        :total="tableData.length"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[2, 5, 10, 50]"
        :page-size="pageSize"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import qs from 'qs'
export default {
  name: 'evaluation',
  data() {
    return {
      s_review:'',
      Httphead:'http://172.16.113.53:9999',
      tableData: [],
      searchData: [],
      selData: [],
      searchValue: '',
      currentPage: 1, //放当前页
      pageSize: 5, //每页条数
      value: '',
    }
  },
  computed: {
    showTableData() {
      let start = this.pageSize * (this.currentPage - 1)
      let end = start + this.pageSize
      let data = this.tableData.slice(start, end)
      return data
    },
  },

  methods: {
    //和分页相关的函数
    //每页多少条数据被改变的时候触发的函数
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`)
      this.pageSize = val
    },
    //当前页被改变的时候触发的函数
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`)
      this.currentPage = val
    },
    //查询所有评价数据
    getORder() {
      this.$axios({
        url: this.Httphead + '/comment/queryOrderList',
        method: 'post',
      })
        .then((res) => {
          console.log('获取所有评价信息', res)
          if (res.code === 200) {
            this.tableData = res.data.data
          } else {
            this.$message({
              message: '服务器出错了',
              type: 'error',
            })
          }
        })
        .catch((err) => {
          console.log('获取评价失败', err)
        })
    },

    //删除评价
    //点击删除
    del(id) {
      // console.log(id);
      this.$confirm('此操作将永久删除该评价, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          //点击了确定按钮
          //发送请求
          this.$axios({
            url: this.Httphead + '/comment/deleteOrder',
            method: 'post',
            data: qs.stringify({
              id: id,
            }),
          })
            .then((res) => {
              // console.log('删除评价信息',res);
              if (res.code === 200) {
                this.$message({
                  type: 'success',
                  message: '删除成功!',
                })
                this.getORder()
                console.log(this.tableData)
              } else {
                this.$message({
                  type: 'error',
                  message: '删除失败!',
                })
              }
            })
            .catch((err) => {
              console.log('错误了', err)
            })
        })
        .catch(() => {
          //点击了取消按钮
          this.$message({
            type: 'info',
            message: '已取消删除',
          })
        })
    },

    //模糊查询
    search() {
      this.$axios({
        url: this.Httphead + '/comment/getByLike',
        method: 'get',
        params: {
          like: this.searchValue,
        },
      }).then((res) => {
          console.log('查询到的数据', res.data)
          if (res.code === 200) {
            this.tableData = res.data
            this.$message({
              type: 'success',
              message: '查询成功!',
            })
          } else {
            this.$message({
              type: 'error',
              message: '查询失败!',
            })
          }
        }).catch((err) => {
          console.log('查询失败', err)
        })
    },
  },
  mounted() {},

  watch: {},
  created() {
    this.getORder()
  },
}
</script>

<style scoped>
#gun {
  color: #0082cc;
}
#search {
  width: 100%;
  height: 60px;
  /* border: 1px solid red; */
  text-align: left;
}

.el-input {
  width: 200px;
  height: 60px;
  margin-right: 20px;
}

.block {
  text-align: center;
}
</style>
